<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/18 0018
 * Time: 16:40
 */

namespace distribution;


use app\lib\dadaapi\ToolsInco;
use app\lib\dadaapi\DadaOpenapi;
use think\Controller;

class MerchantApi extends Controller
{

    public function add($param){
      $tools = new ToolsInco();
      $config = $tools->getDataConfig();
      $config['url'] = $config['url'].'/api/shop/add';
      $dadaOpenApi = new DadaOpenapi($config);
        $reqStatus = $dadaOpenApi->makeRequest($param);
        if (!$reqStatus) {
            //接口请求正常，判断接口返回的结果，自定义业务操作
            if ($dadaOpenApi->getCode() == 0) {
                //返回成功
                $returnData['result'] = $dadaOpenApi->getResult();
                $returnData['code'] =$dadaOpenApi->getCode();
                $returnData['msg'] =$dadaOpenApi->getMsg();
                $returnData['status'] =$dadaOpenApi->getStatus();
                return $returnData;
            }else{
                //返回失败
                $returnData['code'] =$dadaOpenApi->getCode();
                $returnData['msg'] =$dadaOpenApi->getMsg();
                $returnData['status'] =$dadaOpenApi->getStatus();
                return $returnData;
            }
        }else{
            //返回失败
            $returnData['code'] ="-100";
            $returnData['msg'] ="请求失败";
            $returnData['status'] ="fail";
            return $returnData;
        }

    }

    /**
     *
     */
    public function edit($data){
        $toole = new ToolsInco();
        $config = $toole->getDataConfig();
        $config['url']=$config['url'].'/api/shop/update';
        $openApi = new DadaOpenapi($config);
        $res = $openApi->makeRequest($data);
        return $res;
    }



}